home *** CD-ROM | disk | FTP | other *** search
/ PC for Alla 2005 May / PC för Alla 0505.iso / fullversioner / realsoft3d / data1.cab / Scripting / scripting / Intro / gadgets.js < prev    next >
Encoding:
Text File  |  2005-04-04  |  5.5 KB  |  191 lines

  1.  
  2. // JavaScript sample demonstrating how to create various GUI objects.
  3. // Copyrights 2002, Realsoft Graphics Oy
  4.  
  5. // --- include java script classes --- 
  6.  
  7. include("oops/r3button.js");
  8. include("oops/r3window.js");
  9. include("oops/r3packer.js");
  10. include("oops/r3slider.js");
  11. include("oops/r3string.js");
  12. include("oops/r3checkb.js");
  13. include("oops/r3text.js");
  14. include("oops/r3cycle.js");
  15. include("oops/r3listv.js");
  16. include("real/gadget/r3vectg.js");
  17. include("real/gadget/r3floatg.js");
  18.  
  19.  
  20. {
  21.     
  22. // --- Callback functions ---
  23.  
  24. function mySliderHook(obj, event, value)
  25. {
  26.     if(event == R3OGM_GADGETDOWN) 
  27.         obj.info.SetText("Down = " + value);
  28.     else if(event == R3OGM_GADGETSCROLL)
  29.         obj.info.SetText("Scroll = " + value);
  30.     else if(event == R3OGM_GADGETUP) 
  31.         obj.info.SetText("Up = " + value);
  32. }
  33.  
  34. function myStringHook(obj, event, value)
  35. {
  36.     if(event == R3OGM_GADGETUP) 
  37.         obj.info.SetText("You entered string " + value);
  38. }
  39.  
  40. function myButtonHook(obj, event, value)
  41. {
  42.     sName = obj.GetText();
  43.  
  44.     if(event == R3OGM_GADGETUP) 
  45.         obj.info.SetText(sName + " clicked");
  46. }
  47.  
  48. function myCheckboxHook(obj, event, value)
  49. {
  50.     if(value == TRUE) 
  51.         obj.info.SetText("Check box checked");
  52.     else 
  53.         obj.info.SetText("Check box cleared");
  54. }
  55.  
  56. function myVectorHook(obj, event, value)
  57. {
  58.     if(event == R3OGM_GADGETUP) 
  59.         obj.info.SetText("Vector [" + value.x + ", " + value.y + ", " + value.z + "] entered");
  60. }
  61.  
  62. function myDuplicateHook(obj, event, value)
  63. {
  64.     var v;
  65.  
  66.     v = obj.vector.GetValue(); // fetch the current value
  67.     v.fmul(2.0);  // multiply by two
  68.     obj.vector.SetValue(v);     // set back 
  69.     obj.info.SetText("Current value duplicated");
  70. }
  71.  
  72. function myResetHook(obj, event, value)
  73. {
  74.     obj.info.SetText("Welcome to JavaScript");
  75.  
  76.     v = new r3Vect(0, 0, 0);
  77.     obj.vector.SetValue(v);
  78. }
  79.  
  80. function myListviewHook(obj, event, value)
  81. {
  82.     obj.info.SetText("Selected " + value);
  83. }
  84.  
  85. // --- create  a new window, as usual --- 
  86.  
  87. window = new r3Window(R3WGA_Parent, _r3gui,
  88.                       R3WGA_Left, 200,
  89.                       R3WGA_Top, 100,
  90.                   R3WA_Title, "Callback Sample",
  91.                       R3WA_ReportCloseWindow, TRUE,
  92.                       R3WA_ReportNewSize, TRUE);
  93.  
  94.  
  95. // --- create couple of gadgets with callbacks --- 
  96.  
  97. slider = new r3Slider(R3WGA_Parent, window,
  98.                       R3GA_Text, "My slider",
  99.                       R3GA_ToolTip, "Slider example",
  100.               R3RA_Hook, mySliderHook,
  101.               R3GSLA_Level, 20,
  102.                       R3GSLA_Min, 0,
  103.                       R3GSLA_Max, 100);
  104.  
  105. string = new r3String(R3WGA_Parent, window,
  106.                       R3GA_Text, "String",
  107.                       R3GA_ToolTip, "Enter string to this field",
  108.                       R3GSA_String, "This is a string",
  109.               R3RA_Hook, myStringHook);
  110.  
  111. checkbox = new r3Checkbox(R3WGA_Parent, window,
  112.                           R3RA_Hook, myCheckboxHook,
  113.                           R3GA_Text, "Check box",
  114.                           R3GA_ToolTip, "This is a tool tip",
  115.                           R3GCBA_Checked, TRUE); // make it checked 
  116.                       
  117. vector = new r3Vectorgadget(R3GA_Text, "Vector",
  118.                       R3RA_Hook, myVectorHook,
  119.                       R3VCGA_Vector, new r3Vect(0.1, 0.2, 0.0), // current value
  120.                       R3WGA_Parent, window);
  121.  
  122. info = new r3Text(R3WGA_Parent, window,
  123.                   R3GA_Text, "Info",
  124.                   R3GTA_Text, "Welcome to JavaScript",  // current value
  125.                   R3GTA_Border, TRUE);
  126.                   
  127. button = new r3Button(R3GA_Text, "My button",
  128.                       R3RA_Hook, myButtonHook,
  129.                       R3WGA_Parent, window);
  130.  
  131. button2 = new r3Button(R3GA_Text, "Duplicate",
  132.                       R3RA_Hook, myDuplicateHook,
  133.                       R3WGA_Parent, window);
  134.  
  135. button3 = new r3Button(R3GA_Text, "Reset",
  136.                       R3RA_Hook, myResetHook,
  137.                       R3WGA_Parent, window);
  138.  
  139.  
  140. list = new r3List();
  141. list.addhead(new r3Root(R3RA_Name, "Monday"));
  142. list.addhead(new r3Root(R3RA_Name, "Tuesday"));
  143. list.addhead(new r3Root(R3RA_Name, "Wednesday"));
  144.                       
  145. listv = new r3Listview(R3GA_Text, "List View",
  146.                        R3RA_Hook, myListviewHook,
  147.                        R3GLVA_List, list,
  148.                        R3WGA_Parent, window);
  149.  
  150.  
  151.  
  152. // --- Design layout for the GUI  ---- 
  153.  
  154. packer = new r3Packer(R3PA_Orientation, R3PAOF_VERTICAL);
  155.  
  156. packer.ADD(R3PAPF_FILLX, R3PAAF_ALIGN, slider);
  157. packer.ADD(R3PAPF_FILLX, R3PAAF_ALIGN, string);
  158. packer.ADD(R3PAPF_FILLX, R3PAAF_ALIGN, vector);
  159. packer.ADD(0, R3PAAF_ALIGN, checkbox);
  160. packer.ADD(R3PAPF_FILLX, R3PAAF_ALIGN, info);
  161. packer.ADD(R3PAPF_FILLX | R3PAPF_FILLY, 0, listv);
  162.  
  163. // put buttons into a horizontal sub packer
  164. subp = new r3Packer(R3PA_Orientation, R3PAOF_HORIZONTAL);
  165. subp.ADD(R3PAPF_FILLX, 0, button);
  166. subp.ADD(R3PAPF_FILLX, 0, button2);
  167. subp.ADD(R3PAPF_FILLX, 0, button3);
  168. packer.ADD(R3PAPF_FILLX, 0, subp);
  169.  
  170. window.SetGmanager(packer);
  171.  
  172. // add 'info' gadget to all gadgets so that they can print
  173. // some information to the read only text gadget from their callbacks
  174. slider.info = info;
  175. button.info = info;
  176. checkbox.info = info;
  177. string.info = info;
  178. vector.info = info;
  179. listv.info = info;
  180. button2.vector = vector;
  181. button2.info = info;
  182. button3.vector = vector;
  183. button3.info = vector;
  184.  
  185. // --- compute native size, show ---
  186.  
  187. window.FIT(R3WFP_BESTFIT);
  188. window.REALIZE();
  189. }
  190.  
  191.